package com.xiaohei.question.controller;

import com.xiaohei.question.pojo.Question;
import com.xiaohei.question.service.QuestionService;
import entity.PageResult;
import entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: ZhangYongLiang
 * @Date: 2020/11/15 10:10
 **/
@Api(value = "每日一题")
@RestController
@CrossOrigin
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    @ApiOperation(value = "随机一题")
    @PostMapping("/randomQ")
    public Result<Question> randomQuestion(){
        Question randQuestion = questionService.randomQuestion();
        return new Result<>(true,20000,"随机一题",randQuestion);
    }

    @ApiOperation(value = "查询接口")
    @PostMapping("/queryTotal")
    public Result<Question> queryTotal(int pageNum, int pageSize) {
        PageResult quesList = questionService.queryTotal(pageNum, pageSize);
        return new Result<>(true,20000,"查询成功",quesList);
    }

    @ApiOperation(value ="新增接口")
    @ResponseBody
    @PostMapping("/add")
    public Result<?> add(@RequestBody Question question) {
        questionService.add(question);
        return new Result<>(true,20000,"查询成功");
    }

    @ApiOperation(value = "删除接口")
    @PostMapping("/delete")
    public Result<?> delete(@PathVariable("id")Integer id) {
        questionService.delete(id);
        return new Result<>(true,20000,"删除成功");
    }


}
